{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import requests\n",
    "import time\n",
    "from lxml import etree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "190\n",
      "140.5\n",
      "158\n",
      "145\n",
      "304\n",
      "630\n",
      "114.8\n",
      "115.5\n",
      "200\n",
      "135\n"
     ]
    }
   ],
   "source": [
    "#设置列表页URL的固定部分\n",
    "url='http://gz.lianjia.com/chengjiao/'\n",
    "#设置页面页的可变部分\n",
    "page=('pg')\n",
    "#设置请求头部信息\n",
    "headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',\n",
    "'Accept':'text/html;q=0.9,*/*;q=0.8',\n",
    "'Accept-Charset':'ISO-8859-1,utf-8;q=0.7,*;q=0.3',\n",
    "'Accept-Encoding':'gzip',\n",
    "'Connection':'close',\n",
    "'Referer':'http://www.baidu.com/link?url=_andhfsjjjKRgEWkj7i9cFmYYGsisrnm2A-TN3XZDQXxvGsM9k9ZZSnikW2Yds4s&amp;amp;wd=&amp;amp;eqid=c3435a7d00146bd600000003582bfd1f'\n",
    "}\n",
    "for i in range(1,80):\n",
    "    if i == 1:\n",
    "        i=str(i)\n",
    "        a=(url+page+i+'/')\n",
    "        r=requests.get(url=a,headers=headers)\n",
    "        html=r.content\n",
    "    else:\n",
    "        i=str(i)\n",
    "        a=(url+page+i+'/')\n",
    "        r=requests.get(url=a,headers=headers)\n",
    "        html2=r.content\n",
    "        html = html + html2\n",
    "    #每次间隔0.5秒\n",
    "    time.sleep(0.5)\n",
    "encoding=requests.get(url,headers=headers).encoding\n",
    "lj=etree.HTML(html,parser=etree.HTMLParser(encoding=encoding))\n",
    "#提取房源总价\n",
    "price=lj.xpath('//div[@class=\"totalPrice\"]')\n",
    "\n",
    "tp=[]\n",
    "for a in price:\n",
    "    totalPrice=a.xpath('.//span/text()')[0]\n",
    "    tp.append(totalPrice)\n",
    "for p in tp[:10]:\n",
    "    print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24517\n",
      "23734\n",
      "23853\n",
      "36840\n",
      "33407\n",
      "46667\n",
      "36854\n",
      "15822\n",
      "33015\n",
      "26492\n"
     ]
    }
   ],
   "source": [
    "#提取房源单价\n",
    "price=lj.xpath('//div[@class=\"unitPrice\"]')\n",
    "\n",
    "up=[]\n",
    "for a in price:\n",
    "    totalPrice=a.xpath('.//span/text()')[0]\n",
    "    up.append(totalPrice)\n",
    "for p in up[:10]:\n",
    "    print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "东北 | 精装 | 有电梯\n",
      "南 | 精装 | 无电梯\n",
      "东 | 精装 | 无电梯\n",
      "南 | 其他\n",
      "南 | 其他 | 有电梯\n",
      "南 | 其他 | 有电梯\n",
      "南 | 其他 | 无电梯\n",
      "南 | 其他\n",
      "东 东南 | 简装 | 无电梯\n",
      "南 | 简装 | 无电梯\n"
     ]
    }
   ],
   "source": [
    "#提取房源信息\n",
    "houseInfo=lj.xpath('//div[@class=\"houseInfo\"]')\n",
    "\n",
    "hi=[]\n",
    "for b in houseInfo:\n",
    "    house=b.xpath('.//text()')[0]\n",
    "    hi.append(house)\n",
    "for i in hi[:10]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "低楼层(共18层) 塔楼\n",
      "中楼层(共7层) 1995年建塔楼\n",
      "高楼层(共6层) 1998年建塔楼\n",
      "低楼层(共8层) 塔楼\n",
      "高楼层(共25层) 2009年建塔楼\n",
      "高楼层(共34层) 2008年建塔楼\n",
      "高楼层(共8层) 塔楼\n",
      "高楼层(共5层) 板楼\n",
      "中楼层(共9层) 1997年建塔楼\n",
      "低楼层(共6层) 板楼\n"
     ]
    }
   ],
   "source": [
    "# 提取位置信息\n",
    "positionInfo=lj.xpath('//div[@class=\"positionInfo\"]')\n",
    "\n",
    "pi=[]\n",
    "for b in positionInfo:\n",
    "    house=b.xpath('.//text()')[0]\n",
    "    pi.append(house)\n",
    "for i in pi[:10]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>unitprice</th>\n",
       "      <th>totalprice</th>\n",
       "      <th>houseinfo</th>\n",
       "      <th>positioninfo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24517</td>\n",
       "      <td>190</td>\n",
       "      <td>东北 | 精装 | 有电梯</td>\n",
       "      <td>低楼层(共18层) 塔楼</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23734</td>\n",
       "      <td>140.5</td>\n",
       "      <td>南 | 精装 | 无电梯</td>\n",
       "      <td>中楼层(共7层) 1995年建塔楼</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23853</td>\n",
       "      <td>158</td>\n",
       "      <td>东 | 精装 | 无电梯</td>\n",
       "      <td>高楼层(共6层) 1998年建塔楼</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>36840</td>\n",
       "      <td>145</td>\n",
       "      <td>南 | 其他</td>\n",
       "      <td>低楼层(共8层) 塔楼</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>33407</td>\n",
       "      <td>304</td>\n",
       "      <td>南 | 其他 | 有电梯</td>\n",
       "      <td>高楼层(共25层) 2009年建塔楼</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  unitprice totalprice      houseinfo        positioninfo\n",
       "0     24517        190  东北 | 精装 | 有电梯        低楼层(共18层) 塔楼\n",
       "1     23734      140.5   南 | 精装 | 无电梯   中楼层(共7层) 1995年建塔楼\n",
       "2     23853        158   东 | 精装 | 无电梯   高楼层(共6层) 1998年建塔楼\n",
       "3     36840        145         南 | 其他         低楼层(共8层) 塔楼\n",
       "4     33407        304   南 | 其他 | 有电梯  高楼层(共25层) 2009年建塔楼"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#导入pandas库\n",
    "import pandas as pd\n",
    "#创建数据表\n",
    "house=pd.DataFrame({'unitprice':up,'totalprice':tp,'houseinfo':hi,'positioninfo':pi})\n",
    "#查看数据表的内容\n",
    "house.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>chaoxiang</th>\n",
       "      <th>zhuangxiu</th>\n",
       "      <th>dianti</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>东</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  chaoxiang zhuangxiu dianti\n",
       "0       东北        精装     有电梯\n",
       "1        南        精装     无电梯\n",
       "2        东        精装     无电梯\n",
       "3        南         其他   None\n",
       "4        南        其他     有电梯"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对房源信息进行分列\n",
    "houseinfo_split = pd.DataFrame((x.split('|') for x in house.houseinfo),index=house.index,columns=['chaoxiang','zhuangxiu','dianti'])\n",
    "houseinfo_split.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>unitprice</th>\n",
       "      <th>totalprice</th>\n",
       "      <th>houseinfo</th>\n",
       "      <th>positioninfo</th>\n",
       "      <th>chaoxiang</th>\n",
       "      <th>zhuangxiu</th>\n",
       "      <th>dianti</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24517</td>\n",
       "      <td>190</td>\n",
       "      <td>东北 | 精装 | 有电梯</td>\n",
       "      <td>低楼层(共18层) 塔楼</td>\n",
       "      <td>东北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23734</td>\n",
       "      <td>140.5</td>\n",
       "      <td>南 | 精装 | 无电梯</td>\n",
       "      <td>中楼层(共7层) 1995年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23853</td>\n",
       "      <td>158</td>\n",
       "      <td>东 | 精装 | 无电梯</td>\n",
       "      <td>高楼层(共6层) 1998年建塔楼</td>\n",
       "      <td>东</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>36840</td>\n",
       "      <td>145</td>\n",
       "      <td>南 | 其他</td>\n",
       "      <td>低楼层(共8层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>33407</td>\n",
       "      <td>304</td>\n",
       "      <td>南 | 其他 | 有电梯</td>\n",
       "      <td>高楼层(共25层) 2009年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46667</td>\n",
       "      <td>630</td>\n",
       "      <td>南 | 其他 | 有电梯</td>\n",
       "      <td>高楼层(共34层) 2008年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>36854</td>\n",
       "      <td>114.8</td>\n",
       "      <td>南 | 其他 | 无电梯</td>\n",
       "      <td>高楼层(共8层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>15822</td>\n",
       "      <td>115.5</td>\n",
       "      <td>南 | 其他</td>\n",
       "      <td>高楼层(共5层) 板楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>33015</td>\n",
       "      <td>200</td>\n",
       "      <td>东 东南 | 简装 | 无电梯</td>\n",
       "      <td>中楼层(共9层) 1997年建塔楼</td>\n",
       "      <td>东 东南</td>\n",
       "      <td>简装</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>26492</td>\n",
       "      <td>135</td>\n",
       "      <td>南 | 简装 | 无电梯</td>\n",
       "      <td>低楼层(共6层) 板楼</td>\n",
       "      <td>南</td>\n",
       "      <td>简装</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>38818</td>\n",
       "      <td>168</td>\n",
       "      <td>西南 | 其他 | 无电梯</td>\n",
       "      <td>中楼层(共5层) 1980年建板楼</td>\n",
       "      <td>西南</td>\n",
       "      <td>其他</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>45298</td>\n",
       "      <td>366</td>\n",
       "      <td>北 | 其他 | 有电梯</td>\n",
       "      <td>中楼层(共32层) 1999年建塔楼</td>\n",
       "      <td>北</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>65239</td>\n",
       "      <td>615</td>\n",
       "      <td>西南 | 简装 | 有电梯</td>\n",
       "      <td>中楼层(共31层) 2000年建塔楼</td>\n",
       "      <td>西南</td>\n",
       "      <td>简装</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>32639</td>\n",
       "      <td>166</td>\n",
       "      <td>东南 | 其他 | 无电梯</td>\n",
       "      <td>中楼层(共5层) 板楼</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>34329</td>\n",
       "      <td>215</td>\n",
       "      <td>东南 | 其他 | 有电梯</td>\n",
       "      <td>中楼层(共11层) 2001年建塔楼</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>35073</td>\n",
       "      <td>242</td>\n",
       "      <td>东南 | 其他 | 有电梯</td>\n",
       "      <td>中楼层(共32层) 塔楼</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>74124</td>\n",
       "      <td>615</td>\n",
       "      <td>南 北 | 精装 | 有电梯</td>\n",
       "      <td>中楼层(共29层) 2010年建塔楼</td>\n",
       "      <td>南 北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>31353</td>\n",
       "      <td>172</td>\n",
       "      <td>南 | 简装 | 无电梯</td>\n",
       "      <td>低楼层(共9层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>简装</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>44920</td>\n",
       "      <td>271</td>\n",
       "      <td>南 | 精装 | 有电梯</td>\n",
       "      <td>高楼层(共23层) 2002年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>28353</td>\n",
       "      <td>185</td>\n",
       "      <td>东南 | 简装 | 无电梯</td>\n",
       "      <td>低楼层(共7层) 1998年建塔楼</td>\n",
       "      <td>东南</td>\n",
       "      <td>简装</td>\n",
       "      <td>无电梯</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   unitprice totalprice        houseinfo        positioninfo chaoxiang  \\\n",
       "0      24517        190    东北 | 精装 | 有电梯        低楼层(共18层) 塔楼       东北    \n",
       "1      23734      140.5     南 | 精装 | 无电梯   中楼层(共7层) 1995年建塔楼        南    \n",
       "2      23853        158     东 | 精装 | 无电梯   高楼层(共6层) 1998年建塔楼        东    \n",
       "3      36840        145           南 | 其他         低楼层(共8层) 塔楼        南    \n",
       "4      33407        304     南 | 其他 | 有电梯  高楼层(共25层) 2009年建塔楼        南    \n",
       "5      46667        630     南 | 其他 | 有电梯  高楼层(共34层) 2008年建塔楼        南    \n",
       "6      36854      114.8     南 | 其他 | 无电梯         高楼层(共8层) 塔楼        南    \n",
       "7      15822      115.5           南 | 其他         高楼层(共5层) 板楼        南    \n",
       "8      33015        200  东 东南 | 简装 | 无电梯   中楼层(共9层) 1997年建塔楼     东 东南    \n",
       "9      26492        135     南 | 简装 | 无电梯         低楼层(共6层) 板楼        南    \n",
       "10     38818        168    西南 | 其他 | 无电梯   中楼层(共5层) 1980年建板楼       西南    \n",
       "11     45298        366     北 | 其他 | 有电梯  中楼层(共32层) 1999年建塔楼        北    \n",
       "12     65239        615    西南 | 简装 | 有电梯  中楼层(共31层) 2000年建塔楼       西南    \n",
       "13     32639        166    东南 | 其他 | 无电梯         中楼层(共5层) 板楼       东南    \n",
       "14     34329        215    东南 | 其他 | 有电梯  中楼层(共11层) 2001年建塔楼       东南    \n",
       "15     35073        242    东南 | 其他 | 有电梯        中楼层(共32层) 塔楼       东南    \n",
       "16     74124        615   南 北 | 精装 | 有电梯  中楼层(共29层) 2010年建塔楼      南 北    \n",
       "17     31353        172     南 | 简装 | 无电梯         低楼层(共9层) 塔楼        南    \n",
       "18     44920        271     南 | 精装 | 有电梯  高楼层(共23层) 2002年建塔楼        南    \n",
       "19     28353        185    东南 | 简装 | 无电梯   低楼层(共7层) 1998年建塔楼       东南    \n",
       "\n",
       "   zhuangxiu dianti  \n",
       "0        精装     有电梯  \n",
       "1        精装     无电梯  \n",
       "2        精装     无电梯  \n",
       "3         其他   None  \n",
       "4        其他     有电梯  \n",
       "5        其他     有电梯  \n",
       "6        其他     无电梯  \n",
       "7         其他   None  \n",
       "8        简装     无电梯  \n",
       "9        简装     无电梯  \n",
       "10       其他     无电梯  \n",
       "11       其他     有电梯  \n",
       "12       简装     有电梯  \n",
       "13       其他     无电梯  \n",
       "14       其他     有电梯  \n",
       "15       其他     有电梯  \n",
       "16       精装     有电梯  \n",
       "17       简装     无电梯  \n",
       "18       精装     有电梯  \n",
       "19       简装     无电梯  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将分列结果拼接回原数据表\n",
    "house=pd.merge(house,houseinfo_split,right_index=True, left_index=True)\n",
    "house.head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>louceng</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>低</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>高</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>低</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>高</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  louceng\n",
       "0       低\n",
       "1       中\n",
       "2       高\n",
       "3       低\n",
       "4       高"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对位置信息进行分列\n",
    "import re\n",
    "positioninfo_split = pd.DataFrame((re.split(r\"楼.+\\)\", x, maxsplit=0)[0] for x in house.positioninfo),index=house.index,columns=['louceng'])\n",
    "positioninfo_split.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>unitprice</th>\n",
       "      <th>totalprice</th>\n",
       "      <th>houseinfo</th>\n",
       "      <th>positioninfo</th>\n",
       "      <th>chaoxiang</th>\n",
       "      <th>zhuangxiu</th>\n",
       "      <th>dianti</th>\n",
       "      <th>louceng</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24517</td>\n",
       "      <td>190</td>\n",
       "      <td>东北 | 精装 | 有电梯</td>\n",
       "      <td>低楼层(共18层) 塔楼</td>\n",
       "      <td>东北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>低</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23734</td>\n",
       "      <td>140.5</td>\n",
       "      <td>南 | 精装 | 无电梯</td>\n",
       "      <td>中楼层(共7层) 1995年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23853</td>\n",
       "      <td>158</td>\n",
       "      <td>东 | 精装 | 无电梯</td>\n",
       "      <td>高楼层(共6层) 1998年建塔楼</td>\n",
       "      <td>东</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>高</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>36840</td>\n",
       "      <td>145</td>\n",
       "      <td>南 | 其他</td>\n",
       "      <td>低楼层(共8层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>None</td>\n",
       "      <td>低</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>33407</td>\n",
       "      <td>304</td>\n",
       "      <td>南 | 其他 | 有电梯</td>\n",
       "      <td>高楼层(共25层) 2009年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46667</td>\n",
       "      <td>630</td>\n",
       "      <td>南 | 其他 | 有电梯</td>\n",
       "      <td>高楼层(共34层) 2008年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>36854</td>\n",
       "      <td>114.8</td>\n",
       "      <td>南 | 其他 | 无电梯</td>\n",
       "      <td>高楼层(共8层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>高</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>15822</td>\n",
       "      <td>115.5</td>\n",
       "      <td>南 | 其他</td>\n",
       "      <td>高楼层(共5层) 板楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>None</td>\n",
       "      <td>高</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>33015</td>\n",
       "      <td>200</td>\n",
       "      <td>东 东南 | 简装 | 无电梯</td>\n",
       "      <td>中楼层(共9层) 1997年建塔楼</td>\n",
       "      <td>东 东南</td>\n",
       "      <td>简装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>26492</td>\n",
       "      <td>135</td>\n",
       "      <td>南 | 简装 | 无电梯</td>\n",
       "      <td>低楼层(共6层) 板楼</td>\n",
       "      <td>南</td>\n",
       "      <td>简装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>38818</td>\n",
       "      <td>168</td>\n",
       "      <td>西南 | 其他 | 无电梯</td>\n",
       "      <td>中楼层(共5层) 1980年建板楼</td>\n",
       "      <td>西南</td>\n",
       "      <td>其他</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>45298</td>\n",
       "      <td>366</td>\n",
       "      <td>北 | 其他 | 有电梯</td>\n",
       "      <td>中楼层(共32层) 1999年建塔楼</td>\n",
       "      <td>北</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>65239</td>\n",
       "      <td>615</td>\n",
       "      <td>西南 | 简装 | 有电梯</td>\n",
       "      <td>中楼层(共31层) 2000年建塔楼</td>\n",
       "      <td>西南</td>\n",
       "      <td>简装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>32639</td>\n",
       "      <td>166</td>\n",
       "      <td>东南 | 其他 | 无电梯</td>\n",
       "      <td>中楼层(共5层) 板楼</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>34329</td>\n",
       "      <td>215</td>\n",
       "      <td>东南 | 其他 | 有电梯</td>\n",
       "      <td>中楼层(共11层) 2001年建塔楼</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>35073</td>\n",
       "      <td>242</td>\n",
       "      <td>东南 | 其他 | 有电梯</td>\n",
       "      <td>中楼层(共32层) 塔楼</td>\n",
       "      <td>东南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>74124</td>\n",
       "      <td>615</td>\n",
       "      <td>南 北 | 精装 | 有电梯</td>\n",
       "      <td>中楼层(共29层) 2010年建塔楼</td>\n",
       "      <td>南 北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>31353</td>\n",
       "      <td>172</td>\n",
       "      <td>南 | 简装 | 无电梯</td>\n",
       "      <td>低楼层(共9层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>简装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>44920</td>\n",
       "      <td>271</td>\n",
       "      <td>南 | 精装 | 有电梯</td>\n",
       "      <td>高楼层(共23层) 2002年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>28353</td>\n",
       "      <td>185</td>\n",
       "      <td>东南 | 简装 | 无电梯</td>\n",
       "      <td>低楼层(共7层) 1998年建塔楼</td>\n",
       "      <td>东南</td>\n",
       "      <td>简装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   unitprice totalprice        houseinfo        positioninfo chaoxiang  \\\n",
       "0      24517        190    东北 | 精装 | 有电梯        低楼层(共18层) 塔楼       东北    \n",
       "1      23734      140.5     南 | 精装 | 无电梯   中楼层(共7层) 1995年建塔楼        南    \n",
       "2      23853        158     东 | 精装 | 无电梯   高楼层(共6层) 1998年建塔楼        东    \n",
       "3      36840        145           南 | 其他         低楼层(共8层) 塔楼        南    \n",
       "4      33407        304     南 | 其他 | 有电梯  高楼层(共25层) 2009年建塔楼        南    \n",
       "5      46667        630     南 | 其他 | 有电梯  高楼层(共34层) 2008年建塔楼        南    \n",
       "6      36854      114.8     南 | 其他 | 无电梯         高楼层(共8层) 塔楼        南    \n",
       "7      15822      115.5           南 | 其他         高楼层(共5层) 板楼        南    \n",
       "8      33015        200  东 东南 | 简装 | 无电梯   中楼层(共9层) 1997年建塔楼     东 东南    \n",
       "9      26492        135     南 | 简装 | 无电梯         低楼层(共6层) 板楼        南    \n",
       "10     38818        168    西南 | 其他 | 无电梯   中楼层(共5层) 1980年建板楼       西南    \n",
       "11     45298        366     北 | 其他 | 有电梯  中楼层(共32层) 1999年建塔楼        北    \n",
       "12     65239        615    西南 | 简装 | 有电梯  中楼层(共31层) 2000年建塔楼       西南    \n",
       "13     32639        166    东南 | 其他 | 无电梯         中楼层(共5层) 板楼       东南    \n",
       "14     34329        215    东南 | 其他 | 有电梯  中楼层(共11层) 2001年建塔楼       东南    \n",
       "15     35073        242    东南 | 其他 | 有电梯        中楼层(共32层) 塔楼       东南    \n",
       "16     74124        615   南 北 | 精装 | 有电梯  中楼层(共29层) 2010年建塔楼      南 北    \n",
       "17     31353        172     南 | 简装 | 无电梯         低楼层(共9层) 塔楼        南    \n",
       "18     44920        271     南 | 精装 | 有电梯  高楼层(共23层) 2002年建塔楼        南    \n",
       "19     28353        185    东南 | 简装 | 无电梯   低楼层(共7层) 1998年建塔楼       东南    \n",
       "\n",
       "   zhuangxiu dianti louceng  \n",
       "0        精装     有电梯       低  \n",
       "1        精装     无电梯       中  \n",
       "2        精装     无电梯       高  \n",
       "3         其他   None       低  \n",
       "4        其他     有电梯       高  \n",
       "5        其他     有电梯       高  \n",
       "6        其他     无电梯       高  \n",
       "7         其他   None       高  \n",
       "8        简装     无电梯       中  \n",
       "9        简装     无电梯       低  \n",
       "10       其他     无电梯       中  \n",
       "11       其他     有电梯       中  \n",
       "12       简装     有电梯       中  \n",
       "13       其他     无电梯       中  \n",
       "14       其他     有电梯       中  \n",
       "15       其他     有电梯       中  \n",
       "16       精装     有电梯       中  \n",
       "17       简装     无电梯       低  \n",
       "18       精装     有电梯       高  \n",
       "19       简装     无电梯       低  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "house=pd.merge(house,positioninfo_split,right_index=True, left_index=True)\n",
    "house.head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "越秀岭南雅筑 2室2厅 77.5平米\n",
      "富丽家园乳芳园 2室1厅 59.2平米\n",
      "远景新苑 3室1厅 66.24平米\n",
      "六榕路福泉一巷 2室1厅 39.36平米\n",
      "万科新里程 3室2厅 91平米\n",
      "荔港南湾 4室2厅 135平米\n",
      "东风西路广雅前街 2室1厅 31.15平米\n",
      "环城西路工农大街 3室1厅 73平米\n",
      "棠德花园 2室1厅 60.58平米\n",
      "鹤洞路鹤建里 2室1厅 50.96平米\n"
     ]
    }
   ],
   "source": [
    "# 提取房名信息\n",
    "housingInfo=lj.xpath('//div[@class=\"title\"]')\n",
    "\n",
    "hoi=[]\n",
    "for b in housingInfo:\n",
    "    hou=b.xpath('.//a/text()')\n",
    "    hoi.append(hou)\n",
    "hoi = [x[0] for x in hoi if x!=[]]\n",
    "hoi = [x for x in hoi if x!='去登录']\n",
    "for i in hoi[:10]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>allinfo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>越秀岭南雅筑 2室2厅 77.5平米</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>富丽家园乳芳园 2室1厅 59.2平米</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>远景新苑 3室1厅 66.24平米</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>六榕路福泉一巷 2室1厅 39.36平米</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>万科新里程 3室2厅 91平米</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                allinfo\n",
       "0    越秀岭南雅筑 2室2厅 77.5平米\n",
       "1   富丽家园乳芳园 2室1厅 59.2平米\n",
       "2     远景新苑 3室1厅 66.24平米\n",
       "3  六榕路福泉一巷 2室1厅 39.36平米\n",
       "4       万科新里程 3室2厅 91平米"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "housingInfo=pd.DataFrame({'allinfo':hoi})\n",
    "#查看数据表的内容\n",
    "housingInfo.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>xiaoqu</th>\n",
       "      <th>huxing</th>\n",
       "      <th>daxiao</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>越秀岭南雅筑</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>77.5平米</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>富丽家园乳芳园</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>59.2平米</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>远景新苑</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>66.24平米</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>六榕路福泉一巷</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>39.36平米</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>万科新里程</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>91平米</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    xiaoqu huxing   daxiao\n",
       "0   越秀岭南雅筑   2室2厅   77.5平米\n",
       "1  富丽家园乳芳园   2室1厅   59.2平米\n",
       "2     远景新苑   3室1厅  66.24平米\n",
       "3  六榕路福泉一巷   2室1厅  39.36平米\n",
       "4    万科新里程   3室2厅     91平米"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "housinginfo_split = pd.DataFrame((x.split(' ') for x in housingInfo.allinfo),index=housingInfo.index,columns=['xiaoqu','huxing','daxiao'])\n",
    "housinginfo_split.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>77.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>59.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>66.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>39.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    size\n",
       "0   77.5\n",
       "1   59.2\n",
       "2  66.24\n",
       "3  39.36\n",
       "4     91"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "daxiao_split = pd.DataFrame((x.split('平米') for x in housinginfo_split.daxiao),index=housingInfo.index,columns=['size','a'])\n",
    "daxiao_split.drop(['a'],axis=1,inplace=True)\n",
    "daxiao_split.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>main_room</th>\n",
       "      <th>sub_room</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  main_room sub_room\n",
       "0         2        2\n",
       "1         2        1\n",
       "2         3        1\n",
       "3         2        1\n",
       "4         3        2"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "huxing_split = pd.DataFrame((re.split('[\"室\",\"厅\"]',x) for x in housinginfo_split.huxing),index=housingInfo.index,columns=['main_room','sub_room', 'a'])\n",
    "huxing_split.drop(['a'],axis=1,inplace=True)\n",
    "huxing_split.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>xiaoqu</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>越秀岭南雅筑</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>富丽家园乳芳园</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>远景新苑</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>六榕路福泉一巷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>万科新里程</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    xiaoqu\n",
       "0   越秀岭南雅筑\n",
       "1  富丽家园乳芳园\n",
       "2     远景新苑\n",
       "3  六榕路福泉一巷\n",
       "4    万科新里程"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "housinginfo_split.drop(['huxing','daxiao'],axis=1,inplace=True)\n",
    "housinginfo_split.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>unitprice</th>\n",
       "      <th>totalprice</th>\n",
       "      <th>houseinfo</th>\n",
       "      <th>positioninfo</th>\n",
       "      <th>chaoxiang</th>\n",
       "      <th>zhuangxiu</th>\n",
       "      <th>dianti</th>\n",
       "      <th>louceng</th>\n",
       "      <th>xiaoqu</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24517</td>\n",
       "      <td>190</td>\n",
       "      <td>东北 | 精装 | 有电梯</td>\n",
       "      <td>低楼层(共18层) 塔楼</td>\n",
       "      <td>东北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>低</td>\n",
       "      <td>越秀岭南雅筑</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23734</td>\n",
       "      <td>140.5</td>\n",
       "      <td>南 | 精装 | 无电梯</td>\n",
       "      <td>中楼层(共7层) 1995年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>中</td>\n",
       "      <td>富丽家园乳芳园</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23853</td>\n",
       "      <td>158</td>\n",
       "      <td>东 | 精装 | 无电梯</td>\n",
       "      <td>高楼层(共6层) 1998年建塔楼</td>\n",
       "      <td>东</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>高</td>\n",
       "      <td>远景新苑</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>36840</td>\n",
       "      <td>145</td>\n",
       "      <td>南 | 其他</td>\n",
       "      <td>低楼层(共8层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>None</td>\n",
       "      <td>低</td>\n",
       "      <td>六榕路福泉一巷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>33407</td>\n",
       "      <td>304</td>\n",
       "      <td>南 | 其他 | 有电梯</td>\n",
       "      <td>高楼层(共25层) 2009年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高</td>\n",
       "      <td>万科新里程</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  unitprice totalprice      houseinfo        positioninfo chaoxiang zhuangxiu  \\\n",
       "0     24517        190  东北 | 精装 | 有电梯        低楼层(共18层) 塔楼       东北        精装    \n",
       "1     23734      140.5   南 | 精装 | 无电梯   中楼层(共7层) 1995年建塔楼        南        精装    \n",
       "2     23853        158   东 | 精装 | 无电梯   高楼层(共6层) 1998年建塔楼        东        精装    \n",
       "3     36840        145         南 | 其他         低楼层(共8层) 塔楼        南         其他   \n",
       "4     33407        304   南 | 其他 | 有电梯  高楼层(共25层) 2009年建塔楼        南        其他    \n",
       "\n",
       "  dianti louceng   xiaoqu  \n",
       "0    有电梯       低   越秀岭南雅筑  \n",
       "1    无电梯       中  富丽家园乳芳园  \n",
       "2    无电梯       高     远景新苑  \n",
       "3   None       低  六榕路福泉一巷  \n",
       "4    有电梯       高    万科新里程  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "house=pd.merge(house,housinginfo_split,right_index=True, left_index=True)\n",
    "house.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>unitprice</th>\n",
       "      <th>totalprice</th>\n",
       "      <th>houseinfo</th>\n",
       "      <th>positioninfo</th>\n",
       "      <th>chaoxiang</th>\n",
       "      <th>zhuangxiu</th>\n",
       "      <th>dianti</th>\n",
       "      <th>louceng</th>\n",
       "      <th>xiaoqu</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24517</td>\n",
       "      <td>190</td>\n",
       "      <td>东北 | 精装 | 有电梯</td>\n",
       "      <td>低楼层(共18层) 塔楼</td>\n",
       "      <td>东北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>低</td>\n",
       "      <td>越秀岭南雅筑</td>\n",
       "      <td>77.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23734</td>\n",
       "      <td>140.5</td>\n",
       "      <td>南 | 精装 | 无电梯</td>\n",
       "      <td>中楼层(共7层) 1995年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>中</td>\n",
       "      <td>富丽家园乳芳园</td>\n",
       "      <td>59.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23853</td>\n",
       "      <td>158</td>\n",
       "      <td>东 | 精装 | 无电梯</td>\n",
       "      <td>高楼层(共6层) 1998年建塔楼</td>\n",
       "      <td>东</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>高</td>\n",
       "      <td>远景新苑</td>\n",
       "      <td>66.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>36840</td>\n",
       "      <td>145</td>\n",
       "      <td>南 | 其他</td>\n",
       "      <td>低楼层(共8层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>None</td>\n",
       "      <td>低</td>\n",
       "      <td>六榕路福泉一巷</td>\n",
       "      <td>39.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>33407</td>\n",
       "      <td>304</td>\n",
       "      <td>南 | 其他 | 有电梯</td>\n",
       "      <td>高楼层(共25层) 2009年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高</td>\n",
       "      <td>万科新里程</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  unitprice totalprice      houseinfo        positioninfo chaoxiang zhuangxiu  \\\n",
       "0     24517        190  东北 | 精装 | 有电梯        低楼层(共18层) 塔楼       东北        精装    \n",
       "1     23734      140.5   南 | 精装 | 无电梯   中楼层(共7层) 1995年建塔楼        南        精装    \n",
       "2     23853        158   东 | 精装 | 无电梯   高楼层(共6层) 1998年建塔楼        东        精装    \n",
       "3     36840        145         南 | 其他         低楼层(共8层) 塔楼        南         其他   \n",
       "4     33407        304   南 | 其他 | 有电梯  高楼层(共25层) 2009年建塔楼        南        其他    \n",
       "\n",
       "  dianti louceng   xiaoqu   size  \n",
       "0    有电梯       低   越秀岭南雅筑   77.5  \n",
       "1    无电梯       中  富丽家园乳芳园   59.2  \n",
       "2    无电梯       高     远景新苑  66.24  \n",
       "3   None       低  六榕路福泉一巷  39.36  \n",
       "4    有电梯       高    万科新里程     91  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "house=pd.merge(house,daxiao_split,right_index=True, left_index=True)\n",
    "house.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>unitprice</th>\n",
       "      <th>totalprice</th>\n",
       "      <th>houseinfo</th>\n",
       "      <th>positioninfo</th>\n",
       "      <th>chaoxiang</th>\n",
       "      <th>zhuangxiu</th>\n",
       "      <th>dianti</th>\n",
       "      <th>louceng</th>\n",
       "      <th>xiaoqu</th>\n",
       "      <th>size</th>\n",
       "      <th>main_room</th>\n",
       "      <th>sub_room</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24517</td>\n",
       "      <td>190</td>\n",
       "      <td>东北 | 精装 | 有电梯</td>\n",
       "      <td>低楼层(共18层) 塔楼</td>\n",
       "      <td>东北</td>\n",
       "      <td>精装</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>低</td>\n",
       "      <td>越秀岭南雅筑</td>\n",
       "      <td>77.5</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23734</td>\n",
       "      <td>140.5</td>\n",
       "      <td>南 | 精装 | 无电梯</td>\n",
       "      <td>中楼层(共7层) 1995年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>中</td>\n",
       "      <td>富丽家园乳芳园</td>\n",
       "      <td>59.2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23853</td>\n",
       "      <td>158</td>\n",
       "      <td>东 | 精装 | 无电梯</td>\n",
       "      <td>高楼层(共6层) 1998年建塔楼</td>\n",
       "      <td>东</td>\n",
       "      <td>精装</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>高</td>\n",
       "      <td>远景新苑</td>\n",
       "      <td>66.24</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>36840</td>\n",
       "      <td>145</td>\n",
       "      <td>南 | 其他</td>\n",
       "      <td>低楼层(共8层) 塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>None</td>\n",
       "      <td>低</td>\n",
       "      <td>六榕路福泉一巷</td>\n",
       "      <td>39.36</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>33407</td>\n",
       "      <td>304</td>\n",
       "      <td>南 | 其他 | 有电梯</td>\n",
       "      <td>高楼层(共25层) 2009年建塔楼</td>\n",
       "      <td>南</td>\n",
       "      <td>其他</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高</td>\n",
       "      <td>万科新里程</td>\n",
       "      <td>91</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  unitprice totalprice      houseinfo        positioninfo chaoxiang zhuangxiu  \\\n",
       "0     24517        190  东北 | 精装 | 有电梯        低楼层(共18层) 塔楼       东北        精装    \n",
       "1     23734      140.5   南 | 精装 | 无电梯   中楼层(共7层) 1995年建塔楼        南        精装    \n",
       "2     23853        158   东 | 精装 | 无电梯   高楼层(共6层) 1998年建塔楼        东        精装    \n",
       "3     36840        145         南 | 其他         低楼层(共8层) 塔楼        南         其他   \n",
       "4     33407        304   南 | 其他 | 有电梯  高楼层(共25层) 2009年建塔楼        南        其他    \n",
       "\n",
       "  dianti louceng   xiaoqu   size main_room sub_room  \n",
       "0    有电梯       低   越秀岭南雅筑   77.5         2        2  \n",
       "1    无电梯       中  富丽家园乳芳园   59.2         2        1  \n",
       "2    无电梯       高     远景新苑  66.24         3        1  \n",
       "3   None       低  六榕路福泉一巷  39.36         2        1  \n",
       "4    有电梯       高    万科新里程     91         3        2  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "house=pd.merge(house,huxing_split,right_index=True, left_index=True)\n",
    "house.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "house['unitprice']=pd.to_numeric(house['unitprice'],errors='coerce')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "unitprice        int64\n",
       "totalprice      object\n",
       "houseinfo       object\n",
       "positioninfo    object\n",
       "chaoxiang       object\n",
       "zhuangxiu       object\n",
       "dianti          object\n",
       "louceng         object\n",
       "xiaoqu          object\n",
       "size            object\n",
       "main_room       object\n",
       "sub_room        object\n",
       "dtype: object"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "house.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "unitprice         int64\n",
       "totalprice      float64\n",
       "houseinfo        object\n",
       "positioninfo     object\n",
       "chaoxiang        object\n",
       "zhuangxiu        object\n",
       "dianti           object\n",
       "louceng          object\n",
       "xiaoqu           object\n",
       "size             object\n",
       "main_room        object\n",
       "sub_room         object\n",
       "dtype: object"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "house['totalprice']=house['totalprice'].astype('float64')\n",
    "house.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "house['size']=pd.to_numeric(house['size'],errors='coerce')\n",
    "house['main_room']=pd.to_numeric(house['main_room'],errors='coerce')\n",
    "house['sub_room']=pd.to_numeric(house['sub_room'],errors='coerce')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "unitprice         int64\n",
       "totalprice      float64\n",
       "houseinfo        object\n",
       "positioninfo     object\n",
       "chaoxiang        object\n",
       "zhuangxiu        object\n",
       "dianti           object\n",
       "louceng          object\n",
       "xiaoqu           object\n",
       "size            float64\n",
       "main_room       float64\n",
       "sub_room        float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "house.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "house.to_csv(\"house.csv\",encoding =\"utf-8\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "house.to_excel('house.xls',sheet_name='biubiu')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
